﻿///CircleLine.as 该类为圆切线所创建的图案
//vesion 1.0
//author 夏天的树人
package org.summerTree.graphics
{
	import flash.geom.Point;
	public class CircleLine extends Base
	{

		public function CircleLine()
		{

		}
		override public  function clone():*
		{
			return new CircleLine();
		}
		//创建圆切线曲线图案

		public function CreatCircleLine(radius:Number,line_length:Number,n:int=5):void
		{
			for(var i:int=0;i<360;i+=n)
			{
				drawLine(radius,line_length,i);			
			}
			
		}
		
		private function drawLine(radius:Number,line_length:Number,angle:Number):void
		{	
		       
		   var px:Number=radius * Math.cos(angle * Math.PI / 180);
		   var py:Number=radius * Math.sin(angle * Math.PI / 180);
		   var k:Number=getline_k(angle,radius);

			//直线参数方程
			var start_lineX:Number=px - line_length * Math.cos(k);
			var start_lineY:Number=py - line_length * Math.sin(k);

			var end_lineX:Number=px + line_length * Math.cos(k);
			var end_lineY:Number=py + line_length * Math.sin(k);

			this.graphics.lineStyle(1,0xff0000);

			this.graphics.moveTo(start_lineX,start_lineY);
			this.graphics.lineTo(end_lineX,end_lineY);			
		}
		
		
		//计算圆上任意一点切线的斜率
		private function getline_k(angle:Number,radius:Number):Number
		{
			var px:Number= radius * Math.cos(angle * Math.PI / 180);
			var py:Number= radius * Math.sin(angle * Math.PI / 180);
			var k:Number=- px /py;
			return Math.atan(k);

		}
	}
}